<!--{template common/header_simple_start}-->
<link href="static/jstree/themes/default/style.min.css?{VERHASH}" rel="stylesheet" media="all">
<link rel="stylesheet" href="static/perfect-scrollbar/css/perfect-scrollbar.css?{VERHASH}">
<link rel="stylesheet" href="static/css/common.css">
<link href="dzz/system/css/selfilewindow.css?{VERHASH}" rel="stylesheet" media="all">
<link href="dzz/system/css/select-file.css?{VERHASH}" rel="stylesheet" media="all">
<script type="text/javascript" src="static/js/jquery.leftDrager.js?{VERHASH}"></script>
<style>  
<!--{ if $ _GET [ 'nosearch' ] > 0}-->
.orgtree-search {
    display: none;
}

body {
    padding-bottom: 0;
}

<!--{/if}-->
</style>
<script type="text/javascript">
    var ctrlid = '$ctrlid';
    /*var multiple=parseInt('$_GET[multiple]')>0?true:false;
     var nouser=parseInt('$_GET[nouser]')>0?1:0;
     var stype='$_GET[stype]'?parseInt('$_GET[stype]'):0;//0:可以选择机构和用户；1：仅选择机构和部门：2：仅选择用户
     var moderator=parseInt('$_GET[moderator]')>0?1:0;*/
    var ismobile = '$ismobile' ? 1 : 0;
</script>
<!--{template common/header_simple_end}-->
<!--内容区开始-->
<div class="select-fileall clearfix">
	<div class="select-filetop clearfix bs-top-container">
		<!--地址栏开始-->
		<div class="select-address">
			<div class="address-all">
				<div class="address-goback">
					<a href="javascript:history.back();">
						<span class="dzz dzz-nav-back"></span>
						<span>返回</span>
						<span class="dzz dzz-vline dzz-address-vline"></span>
					</a>
				</div>
				<div class="address-container">
					<div class="address-left-arrow address-arrow"><<</div>
					<div class="address-right-arrow address-arrow">>></div>
					<div class="address-field">
						<li>
							<a href="javascript:;">地址栏</a>
							<span class="dzz dzz-chevron-right"></span>
						</li>
					</div>
					<input type="text" value="地址栏" class="form-control borderInput" />
				</div>
				<input type="hidden" value="$fid" id="fidinput"/>
			</div>
		</div>
		<!--地址栏结束-->
		<div class="select-filetopbottom clearfix">
			<input id="$ctrlid" type="hidden" name="fid" value=""/>
		    <!--{if $allowcreate}-->
		    <button type="button" class="btn btn-primary-outline pull-left" onclick="createNewFolder();return false;">{lang newfolder}</button>
		    <!--{/if}-->
		    <div class="select-filetopright pull-right">
		    	<div class="select-display dropdown">
		    		<button type="text" class="form-control" value="" data-toggle="dropdown" id="select-button">
		    			<span class="select-alltype">全部类型</span>
		    			<span class="dzz dzz-arrow-dropdown dzz-select-button"></span>
		    		</button>
		    		<ul class="dropdown-menu select-type">
		    				<li>
		    				<a href="javascript:;">全部类型</a>
		    			</li>
		    			<li>
		    				<a href="javascript:;">图片</a>
		    			</li>
		    			<li>
		    				<a href="javascript:;">照片</a>
		    			</li>
		    		</ul>
		    	</div>
		    	<input type="text" placeholder="搜索" class="form-control select-display"/>
		    	<div class="select-change select-display">
		    		<a href="javascript:;">
		    			<i class="dzz dzz-layout"></i>
		    		</a>
		    	</div>
		    </div>
		</div>
	</div>
	<div class="select-filecenter bs-container clearfix">
		<div class="bs-left-container scroll-y clearfix">
			<div class="mechsnismMenu" id="position" class="usertree-container list-unstyled"></div>
		</div>
		<div class="left-drager scroll-y">
  		</div>
		<div class="bs-main-container scroll-y">
			<div id="selectfile-f-$fid" class="icosContainer"></div>
		</div>
	</div>
	<div class="select-filebottom clearfix">
		<div class="input-black input-fixation">
			<label class="control-label input-label">文件名:</label>
			<div class="input-animate">
				<input type="text" class="form-control" placeholder="文件名" />
			</div>
		</div>
	</div>
</div>
<!--内容区结束-->
<!--模板开始-->
<div id="template_middleicon" style="display:none">
<!--{template template_file_middleicon}-->
</div>
<div id="template_detaillist"  style="display:none">
<!--{template template_file_detaillist}-->
</div>
<!--模板结束-->
<script type="text/javascript">
//拖拽初始化
jQuery('.left-drager').leftDrager_layout(function(){});
//左侧jstree操作
var opened = {};
/*jstree 左侧个人、机构及群组*/
$(document).ready(function (e) {
//input框初始化开始
$('.input-black').each(function() {			
	InputAnimate.init($(this));	
});
//input框初始化结束
//左侧jstree操作开始
opened = window.opener;
var _explorer = {};
_explorer.jstree = jQuery('#position').jstree({
    "core": {
        "multiple": true,
        "check_callback": true,
        "themes": {
            "responsive": false
        },
        'data': function (node, cb) {
            var self = this;
            $.getJSON('index.php?mod=system&op=positionlist&do=get_children&range={$range}&selhome={$selhome}&selorg={$selorg}&selgroup={$selgroup}', {'id': node.id}, function (json) {
                cb.call(this, json);
            });
        }
    },
    "types": {
        "#": {
            "max_children": -1,
            "max_depth": -1,
            "valid_children": -1
        },
        "organization": {//部门
            "icon": "dzz dzz-account-box",
            "valid_children": ['depart', 'folder']
        },
        "department": {
            "icon": "dzz/system/images/department.png",
            "valid_children": ['depart', 'folder']
        },
        "group": {//群组
            "li_attr": 'aaa',
            "icon": "dzz dzz-group",
            "valid_children": ['folder']
        },
        "home": {//我的网盘
            "icon": "dzz dzz-mydisk",
            "valid_children": ['folder']
        },
        "folder": {//群组
            "icon": "dzz dzz-folder",
            "valid_children": ['folder']
        },
    },
    "plugins": ['types', 'search', 'wholerow']
});

$('#position').off('select_node.jstree').on('select_node.jstree', function (e, data) {
    var inst = $('#position').jstree(true);
    var node = data.node;
    if (!node.li_attr.fid) {
        var replacematch = /^([a-z]|[A-Z])+_/;
        var fid = node.id.replace(replacematch, '');

    } else {
        var fid = node.li_attr.fid;
    }
    var nummatch = /^\d+$/;
    if(nummatch.test(fid)){
        $.post('index.php?mod=system&op=positionlist&do=checkupload',{'fid':fid},function(data){
            if(data['perm']){
                $('#' + ctrlid).val(fid);
            }else{
                inst.deselect_node(node);
                $('#' + ctrlid).val('');
            }
        },'json')
    }else{
        inst.deselect_node(node);
        $('#' + ctrlid).val('');
        }
        inst.open_node(node);
        return false;
    });

//请求fid
var fid = $('#fidinput').val();
_selectfile.fid  = fid;
_selectfile.getData(MOD_URL+'&op=explorerfile&do=filelist&sid=f-'+fid);
});
function createNewFolder() {
    var inst = $('#position').jstree(true);
    var id = $('#position').jstree("get_selected");
    if(id.length < 1){
        showmessage(__lang.please_select_dir,'danger',2000,1);
        return false;
    }else{
        var pnode = inst.get_node(id);
    }
    var fid = '';
    if (!pnode.li_attr.fid) {
        var replacematch = /^([a-z]|[A-Z])+_/;
        fid = pnode.id.replace(replacematch, '');

    } else {
        fid = pnode.li_attr.fid;
    }
    if (!fid) {
        showmessage(__lang.please_select_dir,'danger',2000,1);
        return false;
    } else {
        $.post('index.php?mod=system&op=positionlist&do=getfoldername', {'fid': fid}, function (data) {
            if (data['success']) {
                var node = {
                    'text': data.fname,
                    'icon': "dzz dzz-folder",
                    'id': 'new_folder',
                    'type': "folder",
                };
                inst.create_node(id, node, 'last', function (datas) {
                    inst.open_node(pnode);
                    $('#new_folder').css({'position': 'relative'});
                    var html = '<div id="replace_jstreeli" class="layer" style="position:absolute;top:0px;left:50px;">' +
                        '<input type="text" value="' + data.fname + '" class="nameinput" style="height:24px"/>' +
                        '<button type="button" class="btn btn-primary-outline button-rightcolor" onclick="realcreate(this,' + node.id + ','+pnode.id+')">' +
                        '<span class="dzz dzz-done"></span>' +
                        '</button>' +
                        '<button type="button" class="btn btn-primary-outline button-rightcolor" onclick="canclecreate(this,' + node.id + ')">' +
                        '<span class="dzz dzz-close"></span>' +
                        '</button> ' +
                        '</div>';
                    $('#new_folder').append(html);
                });
            }else{
//                    showDialog(data['error']);
                showmessage(data['error'],"danger",2000,1);
            }
        }, 'json');
        return false;
    }
}
function realcreate(obj, node,parentnode) {
    var inst = $('#position').jstree(true);
    var pnode = inst.get_node(parentnode);
    var fid = '';
    if (!pnode.li_attr.fid) {
        var replacematch = /^([a-z]|[A-Z])+_/;
        fid = pnode.id.replace(replacematch, '');

    } else {
        fid = pnode.li_attr.fid;
    }
    var fname = $(obj).closest('.layer').find('.nameinput').val();
    var empty = /^\s*$/;
    if (empty.test(fname)) {
        showmessage(__lang.name_cannot_empty,"danger",2000,1);
        return false;
    }
    $.post('index.php?mod=system&op=positionlist&do=creatnewfolder',{'fid':fid,'foldername':fname},function(data){
        if(data['msg'] == 'success'){
            inst.rename_node(node, fname);
            inst.set_id(node, 'f_'+data.fid);
            $(obj).closest('.layer').remove();
            inst.deselect_node(parentnode);
            inst.select_node(node);
        }else {
            showmessage(data['error'],"danger",2000,1);
        }
    },'json');
    return false;
}
function canclecreate(obj, node) {
    var inst = $('#position').jstree(true);
    $(obj).closest('.layer').remove();
    inst.delete_node(node);
}
function submitdata(){
    var fid = $('#'+ctrlid).val();
    if(!fid){
//            showDialog(__lang.please_select_dir);
        showmessage(__lang.please_select_dir,"danger",2000,1);
        return false;
    }else{
        $.post(MOD_URL+'&op=positionlist&do=geffolderinfo',{'fid':fid},function(data){
			try{if(typeof parent.showWindow_callback == 'function') parent.showWindow_callback(fid,data);}catch(e){}
            if(parent.$callback){
               try{ parent.$callback(fid,data);}catch(e){}
            }else{
               try{ opened.$callback(fid,data);}catch(e){}
            }
			
            hide_window();
        },'json')
    }
    return false;
}
function hide_window(){
    if(opened){
        window.close();
    }else{
        parent.hide_window();
    }
}


</script>
<!--底部-->
<div class="modal-footer">
    <button type="button" class="btn btn-primary" onclick="submitdata()">{lang confirms}</button>
    <button type="button" class="btn btn-default-outline cancel" data-dismiss="modal" aria-label="Close" onclick="hide_window()">{lang cancel} </button>
</div>
</body>
</html>
<script type="text/javascript" src="static/js/jstree.min.js?{VERHASH}"></script>
<script type="text/javascript" src="dzz/system/scripts/select-file.js?{VERHASH}"></script>
<script type="text/javascript" src="static/perfect-scrollbar/js/perfect-scrollbar.min.js?{VERHASH}"></script>
<script type="text/javascript" src="static/js/input_field.js?{VERHASH}"></script>
<script type="text/javascript" src="static/bootstrap/js/bootstrap.min.js"></script> 